package cn.wit.test;

import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.paint.Color;

/**
 * 画板，内容展示
 * 
 * @author 16604
 *
 */
public class Board extends Canvas {

	private static final int GRID = 20;

	RandomShape randomShape = new RandomShape();

	public Board() {
		setWidth(450);
		setHeight(600);

		int sizeRow = 600 / GRID;
		int sizeCol = 600 / GRID;

		GraphicsContext gc = getGraphicsContext2D();

		gc.setStroke(Color.BLUE);

		// 画横线
		for (int i = 0; i < GRID; i++) {
			gc.strokeLine(0, sizeRow * i, 600, sizeRow * i);
		}
		// 画纵线
		for (int i = 0; i < GRID; i++) {
			gc.strokeLine(sizeCol * i, 0, sizeCol * i, 600);
		}

		draw(gc, sizeRow, sizeCol, 10 * sizeRow, 10 * sizeRow, RandomShape.returnShap());

	}

	// 画一个具体的形状
	public void draw(GraphicsContext gc, int width, int height, int x, int y, int[][] shape) {
		for (int i = 0; i < shape.length; i++) {
			for (int j = 0; j < shape[i].length; j++) {
				if (shape[i][j] == 1) {
					gc.fillRect(j * width, i * height, width, height);
				}
			}
		}
	}
}
